//
// Created by sgyt on 2020/6/1.
// 服务和端口

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <netdb.h>

void print_servent(struct servent *pServent);

int main(int argc, char *argv[])
{
    struct servent *servent;
    setservent(1);

    while ((servent = getservent()) != NULL){
        print_servent(servent);
        printf("\n");
    }

    endnetent();

    return 0;
}

void print_servent(struct servent *pServent) {
    char **aliase;

    printf("port name is %s\n",pServent->s_name);

    for(aliase = pServent->s_aliases;*aliase;aliase++)
    {
        printf("aliase is %s\n",*aliase);
    }

    printf("port is %d\n",pServent->s_port);

    printf("porto is %d\n",pServent->s_proto);

}
